//
//  LZLFindDudCollectionViewCell.swift
//  swiftDemo
//
//  Created by luozhilin on 2018/9/18.
//  Copyright © 2018年 luozhilin. All rights reserved.
//

import UIKit

class LZLFindDudCollectionViewCell: UITableViewCell {
    
    private lazy var iconImage:UIImageView = {
        let iconImage = UIImageView()
        iconImage.layer.cornerRadius = 15
        iconImage.layer.masksToBounds = true
        return iconImage
    }()
    
    private lazy var nameLabel:UILabel = {
        let nameLabel = UILabel()
        nameLabel.font = UIFont.systemFont(ofSize: 15)
        nameLabel.tintColor = UIColor.gray
        return nameLabel
    }()
    
    private lazy var itemImage:UIImageView = {
        let itemImage = UIImageView()
        return itemImage
    }()
    
    private lazy var itemName:UILabel = {
        let itemName = UILabel()
        itemName.font = UIFont.systemFont(ofSize: 15)
        itemName.tintColor = UIColor.white
        return  itemName
    }()
    
    private lazy var priseImage:UIImageView = {
        let priseImage = UIImageView()
        priseImage.image = UIImage(named: "点赞")
        return priseImage
    }()
    
    private lazy var priseCount:UILabel = {
        let priseCount = UILabel()
        priseCount.font = UIFont.systemFont(ofSize: 14)
        priseCount.tintColor = UIColor.gray
        return priseCount
    }()
    
    private lazy var contentImage:UIImageView = {
        let contentImage = UIImageView()
        contentImage.image = UIImage(named: "点评")
        return contentImage
    }()
    
    private lazy var contentCount:UILabel = {
        let contentCount = UILabel()
        contentCount.font = UIFont.systemFont(ofSize: 14)
        contentCount.tintColor = UIColor.gray
        return contentCount
    }()
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUpUI(){
        self.contentView.addSubview(self.itemImage)
        self.contentView.addSubview(self.itemName)
        self.contentView.addSubview(self.iconImage)
        self.contentView.addSubview(self.nameLabel)
        self.contentView.addSubview(self.priseImage)
        self.contentView.addSubview(self.priseCount)
        self.contentView.addSubview(self.contentImage)
        self.contentView.addSubview(self.contentCount)
        
        self.itemImage.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(15)
            make.top.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-15)
            make.bottom.equalToSuperview().offset(-60)
        }
        
        self.itemName.snp.makeConstraints { (make) in
            make.left.top.equalTo(self.itemImage).inset(20)
            make.height.equalTo(20)
        }
        
        self.iconImage.snp.makeConstraints { (make) in
            make.left.equalTo(self.itemImage)
            make.top.equalTo(self.itemImage.snp.bottom).offset(20)
            make.width.height.equalTo(30)
        }
        
        self.nameLabel.snp.makeConstraints { (make) in
            make.left.equalTo(self.iconImage.snp.right).offset(15)
            make.centerY.equalTo(self.iconImage.snp.centerY)
        }
        
        self.contentCount.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-20)
            make.centerY.equalTo(self.iconImage.snp.centerY)
            make.height.equalTo(20)
        }
        
        self.contentImage.snp.makeConstraints { (make) in
            make.width.height.equalTo(25)
            make.centerY.equalTo(self.iconImage.snp.centerY)
            make.right.equalTo(self.contentCount.snp.left).offset(-15)
        }
        
        self.priseCount.snp.makeConstraints { (make) in
            make.centerY.equalTo(self.iconImage.snp.centerY)
            make.right.equalTo(self.contentImage.snp.left).offset(-20)
            make.height.equalTo(20)
        }
        
        self.priseImage.snp.makeConstraints { (make) in
            make.width.height.equalTo(25)
            make.centerY.equalTo(self.iconImage.snp.centerY)
            make.right.equalTo(self.priseCount.snp.left).offset(-15)
        }
    }
    
    // 赋值的模型
    var findDudModel:FindDudModel?{
        didSet{
            guard let model = findDudModel else {
                return
            }
            
            self.iconImage.kf.setImage(with: URL(string: (model.dubbingItem?.coverPath)!))
            self.itemName.text = model.dubbingItem?.intro
            self.iconImage.kf.setImage(with: URL(string: (model.dubbingItem?.logoPic)!))
            self.nameLabel.text = model.dubbingItem?.nickname
            let zanNum:Int = (model.dubbingItem?.favorites)!
            self.priseCount.text = "\(zanNum)"
            let commentNum:Int = (model.dubbingItem?.commentCount)!
            self.contentCount.text = "\(commentNum)"
        }
    }
    
}
















